package org.lakeside.outreach.client;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Project implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String name;
	@Persistent
	private String description;
	@Persistent
	private User user;
	@Persistent
	private Date createDate;
	@Persistent
	private List<Event> events;
	
	public Project() {
		this.createDate = new Date();
	}
	
	public Project(String name, String description, User user) {
		this();
		this.name = name;
		this.description = description;
		this.user = user;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public User getUser() {
		return user;
	}

	public Date getCreateDate() {
		return createDate;
	}
	
	public List<Event> getEvents() {
		return events;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	public void addEvent(Event event) {
		for(Event e: events) {
			if(e.getDate().equals(event.getDate())) {
				return;
			}
		}
		events.add(event);
	}
}
